--存储过程:判断可疑用户
CREATE procedure judge
    @CustomerTel varchar(15),--输入用户手机号
    @status int out
as
begin
    -- 统计订单次数和总金额与评分
    declare @Number int,
        @AllCost int,
        @MerchantMark tinyint
    select @Number=count ( history_order_number),@AllCost=sum(whole_price),@MerchantMark=avg( merchant_order_grade)
    from history_order
    where  customer_phone_number=@CustomerTel
-- 封禁比例
    if  @AllCost < 1000 and @Number>20  and @MerchantMark<6
        begin
            --有问题
            print'该账户存在问题'
            set @status=0
            return
        end
    else if @AllCost < 3000 and @MerchantMark<5
        begin
            --有问题
            print'该账户存在问题';
            set @status=0
            return

        end
    else if @AllCost < 5000 and @MerchantMark<4
        begin
            --有问题
            print'该账户存在问题'
            set @status=0
            return
        end
    else begin
        print '正常';
    end
end
go

